@isTest
private class RejectedGoodApproveRESTTest {
    static testMethod void testMethod1() {
        TestUtils.createUsers();
    	User appMan = [SELECT Id,Name FROM User WHERE Name='用户1' LIMIT 1];
    	//创建客户
    	Account acc = TestUtils.createAccount();
    	insert acc;
        //创建科室
        Department__c dept = TestUtils.createDepartment();
        dept.TerminalCustomer__c = acc.Id;
        insert dept;
        //创建产品
        Product__c pro = TestUtils.createProduct();
        insert pro;
        //创建联系人
        Contact con = TestUtils.createContact();
        con.MobilePhone = '13588885555';
        con.Post__c = '科长/主任';
        insert con;
        //创建合同
        Contract__c ctr = TestUtils.createContract();
        ctr.Account__r = acc;
        insert ctr;
        //创建出库单
        ExWarehouse__c ord = new ExWarehouse__c();
        ord.cgeneralhid__c = '1213';
        ord.corpcode__c = 'nc0012';
        ord.corpname__c = 'nc公司名称';
        ord.Account__c = acc.Id;
        ord.custcode__c = acc.AccountNumber;
        ord.custname__c = acc.Name;
        ord.dbilldate__c = Date.today();
        ord.ckname__c = '成品仓库';
        ord.currtypename__c = 'RMB';
        ord.Name = 'OP.2017010001';
        insert ord;
        //创建出库明细 
        ExWarehouse_Detail__c op = new ExWarehouse_Detail__c();
        op.outcode__c = 'OP.2017010001';
        op.ExWarehouse__c = ord.Id;
        op.Name = '2154';
        op.invcode__c = pro.NCCode__c;
        op.invname__c = pro.Name;
        op.invdm__c = pro.TypeCode__c;
        op.vbatchcode__c ='12';
        op.nnum__c = 231;
        op.sale_hid__c = '5421';
        op.sale_bid__c = '3421';
        op.salecode__c = 'OD.2017010001';
        op.Product__c = pro.Id;
        insert op;
        //创建退货单 
        ReturnOrder__c ro = new ReturnOrder__c();
        ro.ExWarehouse__c = ord.Id;
        ro.Return_Number__c = 20;
        ro.Is_Return_Invoice__c = false;
        ro.Return_Reason__c = '发货错误';
        ro.Other_Reasons__c = '错误类型';
        ro.Contact__c = con.Id;
        ro.ContactDept__c = '检验科';
        ro.Applicant__c = appMan.Id;
        ro.ContactDate__c = Date.valueOf('2017-01-01');
        ro.MakeDate__c = Date.valueOf('2017-01-01');
        ro.Approved_Date__c = Datetime.valueOf('2017-01-02 11:20:00');
        ro.Approve_Status__c = '审批通过';
        ro.Account__c = acc.Id;
        insert ro;

        Test.startTest();
        Map<String,String> args = new Map<String,String>();
        args.put('aaa', '2017-01-01 00:00:00');
        RejectedGoodApproveREST.getApprovedReturnOrder(args);

        args.clear();
        args.put('ts', 'datetime');
        RejectedGoodApproveREST.getApprovedReturnOrder(args);

        args.clear();
        args.put('ts', '2017-01-01 00:00:00');
        RejectedGoodApproveREST.getApprovedReturnOrder(args);

        Test.stopTest();
    }
}